package jee.boot.data.permission.config;

import jee.boot.common.basic.interceptor.InterceptorRegister;
import jee.boot.data.permission.execute.PostQueryExecuteInterceptor;
import jee.boot.data.permission.execute.PreInsertExecuteInterceptor;
import jee.boot.data.permission.execute.PreQueryExecuteInterceptor;
import jee.boot.data.permission.execute.PreUpdateExecuteInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 权限拦截初始化
 */
@Component
public class InitPermission implements ApplicationRunner {

    /**
     * 日志对象
     */
    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private InterceptorRegister interceptorRegister;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        logger.info("权限拦截器初始化");
        interceptorRegister.addPreQueryInterceptor(new PreQueryExecuteInterceptor());
        interceptorRegister.addPreUpdateInterceptor(new PreUpdateExecuteInterceptor());
        interceptorRegister.addPostQueryInterceptor(new PostQueryExecuteInterceptor());
        interceptorRegister.addPreInsertInterceptor(new PreInsertExecuteInterceptor());

    }
}
